package com.xiaren.ui;

import java.awt.HeadlessException;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;

import com.xiaren.comm.DBHelp;
import com.xiaren.comm.Dao;

public class MyTest extends JFrame {

	JButton btn = new JButton("    ");

	JTextPane text = new JTextPane();

	public static void main(String[] args) throws HeadlessException,
			SQLException {
		JOptionPane.showMessageDialog(null, "sdafasd");
//		aa();
	}

	private static void aa() throws SQLException {
		String sql = "select t.id,t.cardnumber,t.boss_id,t.job_no,t.key_name from sys_employee t inner join sys_department d on d.id = t.department_entity left join (select * from rsc_card_data where status = 1) c on t.id = c.user_entity where t.status = 1 and t.cardnumber is null";
		Dao dao = new Dao();
		DBHelp db = new DBHelp();
		Connection conn = db.getConnection(null,
				"jdbc:oracle:thin:@192.168.8.44:1521:ORCL", "NEONONECARD",
				"NEONONECARD");
		List<Object[]> listobj = dao.query(conn, sql);
		
		for (Object[] objects : listobj) {
			String result = "";
			for (Object object : objects) {
				result += object + "\t";
			}
			System.out.println(result);
		}
	}

	private String runInfo() throws SQLException {
		Dao dao = new Dao();
		DBHelp db = new DBHelp();
		Connection conn = db.getConnection(null,
				"jdbc:oracle:thin:@192.168.1.102:1521:ORCL", "neononecard",
				"neononecard");
		String sql = "select key_name from sys_department";
		List<Object[]> listobj = dao.query(conn, sql);
		String result = "";
		for (Object[] objects : listobj) {
			for (Object object : objects) {
				result += object + ",";
			}
		}
		return result;
	}

	public MyTest() throws HeadlessException {
		super();
		init();
	}

	private void init() {
		setDefaultCloseOperation(3);
		setBounds(200, 200, 400, 300);
		this.add(text);
		text.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					try {
						text.setText(runInfo());
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
				}
			}
		});
		setVisible(true);
	}

}
